<template>
  <div>
    <!-- 轮播图 -->
    <mt-swipe :auto="4000">
      <mt-swipe-item v-for="(item,i) in carousel" :key="i">
        <a :href="item.url">
          <!-- <img :src="item.img+'?'+(new Date()).getTime()"> -->
          <img v-lazy="item.img+'?'+(new Date()).getHours()">
        </a>
      </mt-swipe-item>
    </mt-swipe>
    <!-- 九宫格模块展示 -->
    <ul class="mui-table-view mui-grid-view mui-grid-9">
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <router-link to="/news/list">
          <img src="../../images/menu1.png" alt="新闻资讯">
          <div class="mui-media-body">新闻资讯</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <router-link to="/photo/list">
          <img src="../../images/menu2.png" alt="图片分享">
          <div class="mui-media-body">图片分享</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <router-link to="/goods/list">
          <img src="../../images/menu3.png" alt="商品购买">
          <div class="mui-media-body">商品购买</div>
        </router-link>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <a href="#">
          <img src="../../images/menu4.png" alt="留言反馈">
          <div class="mui-media-body">留言反馈</div>
        </a>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <a href="#">
          <img src="../../images/menu5.png" alt="视频专区">
          <div class="mui-media-body">视频专区</div>
        </a>
      </li>
      <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
        <a href="#">
          <img src="../../images/menu6.png" alt="联系我们">
          <div class="mui-media-body">联系我们</div>
        </a>
      </li>
    </ul>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      carousel: [] // 保存轮播图数组
    };
  },
  methods: {
    getCarousel() {
      // 获取轮播图数据
      this.$http.get("getcarousel").then(result => {
        if (result.status === 200) this.carousel = result.body;
        else Toast("轮播图加载失败");
      });
    }
  },
  created() {
    this.getCarousel();
  }
};
</script>

<style lang="scss" scoped>
.mint-swipe {
  height: 200px;
  .mint-swipe-item {
    /* &:nth-child(1) {
      background-color: red;
    }
    &:nth-child(2) {
      background-color: blue;
    }
    &:nth-child(3) {
      background-color: cyan;
    } */
    image {
      width: 100%;
      height: 100%;
      [lazy="loading"] {
        width: 40px;
        height: 300px;
        margin: auto;
      }
    }
  }
}
// 使用原本的样式避免权重问题
.mui-grid-view.mui-grid-9 {
  background-color: #fff;
  .mui-table-view-cell {
    border: 0;
    img {
      width: 60px;
    }
    .mui-media-body {
      font-size: 13px;
    }
  }
}
</style>

